import 'package:flutter/material.dart';
import 'package:framelib/route/navigator.dart';
import 'package:framelib/route/route_config.dart';
import 'package:get/get.dart';
import 'package:moduletwo/module/viewmodel/get_one_view_model.dart';
import '../viewmodel/get_two_list_view_model.dart';

class GetTwoListPage extends StatefulWidget {
  String tag;
  GetTwoListPage({this.tag});
  @override
  _GetTwoListPageState createState() => _GetTwoListPageState();
}

class _GetTwoListPageState extends State<GetTwoListPage> {

  final GetTwoListViewModel getTwoListViewModel=Get.put(GetTwoListViewModel());
  final GetOneViewModel getOneViewModel=Get.find();
  @override
  Widget build(BuildContext context){
    return Container(
      child: Center(
        child: Column(
          children: [
            Text('${widget.tag}'),
            SizedBox(height: 30,),
            Obx(()=>Text('${getOneViewModel.count.obs}')),
            SizedBox(height: 30,),
            FlatButton(onPressed: ()=>getTwoListViewModel.increase(), child: Text('点击当前页面指定前一个页面相加'),color: Colors.amber,),
            SizedBox(height: 30,),
            FlatButton(onPressed: ()=>getOneViewModel.increase(), child: Text('点击相加'),color: Colors.amber,),
            SizedBox(height: 30,),
            FlatButton(onPressed: ()=>_back(), child: Text('点击返回'),color: Colors.amber,),
            SizedBox(height: 30,),
            FlatButton(onPressed: ()=>_toModuleOne(), child: Text('点击进入模块一'),color: Colors.amber,)
          ],
        ),
      ),
    );
  }

  _back() {
    Get.back(result: {'result':'ok'});
  }

  _toModuleOne() {
    NavigatorUtils.pushByName(RouteConfig.moduleOnePage,arguments: {
      'value':'传过来的值为1'
    });
  }
}
